/*
 * Copyright (c) 2014, 2015, XIANDIAN and/or its affiliates. All rights reserved.
 * XIANDIAN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 *
 */
package com.xd.cloud.service.core;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.xd.cloud.dao.Page;
import com.xd.cloud.dao.core.RoleDao;
import com.xd.cloud.dao.core.UserRoleDao;
import com.xd.cloud.entity.core.UserRole;

/**
 * 用户角色service
 * 
 * @author 云计算应用与开发项目组
 * @since V1.0
 * 
 */
@Service
public class UserRoleService {

	@Autowired
	private UserRoleDao userRoleDao;
	@Autowired
	private RoleDao roleDao;

	public UserRole get(int id) {
		return userRoleDao.get(id);
	}
	
	public List<Object> findUserRole(String username)
	{
		return userRoleDao.findUserRole(username);
	}
	
	public void remove(int id) {
		UserRole c = userRoleDao.get(id);
		if (c != null)
			userRoleDao.delete(c);
	}

	public void update(UserRole c) {
		userRoleDao.update(c);
	}

	public boolean save(UserRole c) {
		userRoleDao.save(c);
		return false;
	}

	public List<UserRole> getAll() {
		return userRoleDao.getAll();
	}

	public Page getAllUserByorgid(int pageNo, int pageSize, int orgid) {
		return userRoleDao.getAllUserByorgid(pageNo, pageSize, orgid);
	}

	public List<UserRole> getByuseridNoStatus(int userid) {
		return userRoleDao.getByuseridNoStatus(userid);
	}

	public List<UserRole> getByUidRid(int userid, int roleid) {
		return userRoleDao.getByUidRid(userid, roleid);
	}
	
	public UserRole getByUidRids(int userid,String roles){
		return userRoleDao.getByUidRids(userid, roles);
	}
	public UserRole getByUidRkey(int userid,String rolekey){
		return userRoleDao.getByUidRkey(userid, rolekey);
	}

	public void delByUidRid(int userid, int roleid) {
		userRoleDao.delByUidRid(userid, roleid);
	}
	public void delByUidRids(String userids,int roleid){
		userRoleDao.delByUidRids(userids, roleid);
	}
	public void save(int userid,int roleid){
		UserRole userRole = new UserRole();
		userRole.setUserid(userid);
		userRole.setRole(roleDao.get(roleid));
		userRoleDao.save(userRole);
	}
}
